<template>
	<view class="payment-contanier" v-if="isLoading">
		<view class="residue-time">
			<view class="time-name">剩余时间:</view>
			<u-count-down :time="30 * 60 * 1000" format="DD:HH:mm:ss" autoStart millisecond @change="onChange">
				<view class="time">
					<text class="time__item">{{ timeData.days }}&nbsp;天</text>
					<text class="time__item">{{ timeData.hours>10?timeData.hours:'0'+timeData.hours}}&nbsp;时</text>
					<text class="time__item">{{ timeData.minutes }}&nbsp;分</text>
					<text class="time__item">{{ timeData.seconds }}&nbsp;秒</text>
				</view>
			</u-count-down>
		</view>
		<view class="pay-moeny"><text>¥</text><text class="money">{{order.payPrice}}</text></view>
		<view class="Payment-method">
			<view class="title list-title">支付方式：</view>
			<view class="method-list">
				<view class="item flex-sb">
					<view class="name flex flex-start">
						<u-icon name="weixin-circle-fill" size="25" color="#28C445"></u-icon>
						<text class="text">微信</text>
					</view>
					<radio :checked="payment==0?true:false"></radio>
				</view>
			</view>
		</view>
		<!-- 底部按钮 -->
		<view class="bottom-fixed">
			<view class="bottom-fixed-content">
				<view class="bottom-fixed-btn flex" @click="handlePay()">
					确认支付
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import * as Order from "@/api/order/index.js"
	export default {
		data() {
			return {
				isLoading: false,
				timeData: {},
				payment: 0,
				order: {},
				options: {}
			};
		},
		onLoad(options) {
			this.options = options;
			this.initData();
		},
		methods: {
			onChange(e) {
				this.timeData = e;
			},
			initData() {
				this.getOrderDetail();
			},
			getOrderDetail() {
				const id = this.options.orderId;
				Order.detail({
					orderId: id
				}).then(res => {
					this.order = res.data;
					this.isLoading = true;
				}).catch(err => err)
			},
			handlePay() {
				Order.sendPay({
					orderId: this.options.orderId
				}).then(res => {
					this.paymentOrder(res.data);
				})
			},
			paymentOrder(options) {
				const app=this;
				return new Promise((resolve, reject) => {
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: options.timeStamp,
						nonceStr: options.nonceStr,
						'package': options.packageVal,
						signType: options.signType,
						paySign: options.paySign,
						success: (res) => {
							app.$unts.success('支付成功');
							setTimeout(function(){
								uni.navigateBack({
									delta: 2, //返回层数，2则上上页
								})
							})
							resolve(res)
						},
						fail: (res) => {
							app.$unts.error('订单未支付')
							reject(res);
						}
					})
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.payment-contanier {
		position: relative;
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-bottom: 200rpx;

		.residue-time {
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 28rpx;
			margin: 50rpx 0px 20rpx 0px;

			.time-name {
				margin-right: 10rpx
			}

			.time {
				@include flex;
				align-items: center;

				&__item {
					color: #000;
					font-size: 28rpx;
					text-align: center;
				}
			}
		}

		.pay-moeny {

			.money {
				font-size: 60rpx;
				margin-left: 10rpx;
			}
		}

		.Payment-method {
			margin-top: 100rpx;
			width: calc(100% - 40rpx);
			padding: 30rpx;
			background: #fff;
			border-radius: 20rpx;
			box-shadow: 20px 20px 29px #ebebeb, -10px -10px 10px #ebebeb;

			.title {
				margin-bottom: 20rpx;
			}

			.item {
				padding: 15rpx 0px;

				.name {
					.text {
						font-size: 28rpx;
						margin-left: 15rpx;
					}
				}
			}
		}
	}
</style>